package com.sky.controller.user;

import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.ShoppingCartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/user/shoppingCart")
@Api(tags = "C端购物车相关接口")
public class ShoppingCartController {


    @Autowired
    private ShoppingCartService shoppingCartService;
    /**
     * 添加购物车
     * @param shoppingCartdto
     * @return
     */
    @PostMapping("/add")
    @ApiOperation(value = "添加购物车", notes = "添加购物车")
    public Result add(@RequestBody ShoppingCartDTO shoppingCartdto){
        log.info("添加购物车：{}",shoppingCartdto);
        shoppingCartService.addShoppingCart(shoppingCartdto);
        return Result.success();
    }

    @GetMapping("/list")
    @ApiOperation(value = "查询购物车列表", notes = "查询购物车列表")
    public Result<List<ShoppingCart>> list(){
        log.info("查询购物车列表");
        List<ShoppingCart> list = shoppingCartService.showShoppingCartList();
        return Result.success(list);
    }

    /**
     * 清空购物车
     * @return
     */
    @DeleteMapping("/clean")
    @ApiOperation(value = "清空购物车", notes = "清空购物车")
    public Result clean(){
        log.info("清空购物车");
        shoppingCartService.cleanShoppingCart();
        return Result.success();
    }

    @PostMapping("/sub")
    public Result deleteOne(@RequestBody ShoppingCartDTO shoppingCartdto){
        log.info("删除购物车商品：{}",shoppingCartdto);
        shoppingCartService.deleteOne(shoppingCartdto);
        return Result.success();
    }

}
